﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic.member;

namespace Ulriksen.Umbraco.OpenId
{
    public class DeleteMemberOpenIdEventHandler : ApplicationBase
    {
        public DeleteMemberOpenIdEventHandler()
        {
            Member.BeforeDelete += new Member.DeleteEventHandler(Member_BeforeDelete);
            Member.AfterDelete += new Member.DeleteEventHandler(Member_AfterDelete);
        }

        void Member_AfterDelete(Member sender, umbraco.cms.businesslogic.DeleteEventArgs e)
        {

        }

        void Member_BeforeDelete(Member sender, umbraco.cms.businesslogic.DeleteEventArgs e)
        {
            try
            {
                umbraco.BusinessLogic.Application.SqlHelper.ExecuteNonQuery(
        "DELETE FROM nuMemberOpenid WHERE nodeId = @nodeId",
        umbraco.BusinessLogic.Application.SqlHelper.CreateParameter("@nodeId", sender.Id));
            }
            catch (Exception ex)
            {
                umbraco.BusinessLogic.Log.Add(LogTypes.Error, sender.Id, "OpenId member delete failed " + ex.ToString());
            }
        }
    }
}